﻿using System;
using System.Windows.Navigation;
using Milkify.Interfaces;
using System.Windows.Input;

namespace Milkify.Views
{
    /// <summary>
    /// Interaction logic for ErrorControl.xaml
    /// </summary>
    public partial class ErrorControl : PageFunction<String>, IView
    {
        public ErrorControl()
        {
            InitializeComponent();

            // Workaround for a strange thing with the Hyperlink's command... if we bind to the ViewModel's
            // 'NavigateToErrorHelpCommand' command, we always get a 'null' parameter for some reason...
            //TODO: try to make the ViewModel's command work!
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, Help, CanHelp));
        }

        private void Help(object sender, ExecutedRoutedEventArgs e)
        {
            //TODO: see comment above.
            ((Milkify.Data.ErrorViewData)ViewData).NavigateToErrorHelpCommand.Execute(e.Parameter);
        }

        private void CanHelp(object sender, CanExecuteRoutedEventArgs e)
        {
            //TODO: see comment above.
            e.CanExecute = ((Milkify.Data.ErrorViewData)ViewData).NavigateToErrorHelpCommand.CanExecute(e.Parameter);
        }

        #region IView Members

        public object ViewData
        {
            get { return DataContext; }
            set { DataContext = value; }
        }

        #endregion
    }
}
